<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2017/4/27
 * Time: 16:55
 */

namespace app\front\controller;


class Outcome extends Home
{
    public function index(){
        //出金记录
        $user = db("account_registration")->where("id",$this->userId)->find();
        $records = db("account_capital")->where("catid",2)->where("username",$user['username'])->order("createdate desc")->paginate(15);
        $this->assign("records",$records);
        return $this->fetch();
    }
    public function outmoney(){
        //出金申请
        if(IS_POST){
            $user = db("AccountRegistration")->where("id",$this->userId)->find();
            $post = input('');
            $post['amount'] = $post['amount_cn'];
            $post['amount_us'] = floatval($post['amount_cn'])/1.17;
            $post['createdate'] = date("Y-m-d H:i:s");
            $res = db("account_capital")->data($post)->insert();
            if($res){
                return $this->ret->setCode(0)->setMsg("出金申请成功，请等待审核")->toJson();
            }else{
                return $this->ret->setCode(1)->setMsg("出金申请失败，请重试！")->toJson();
            }
        }else{
            $record = db("account_registration")->where("id",$this->userId)->find();
            $times = db("account_capital")->where("username",$record['username'])->where("catid",2)->where("audit",1)->count();
            $money = db("account_capital")->where("username",$record['username'])->where("catid",2)->where("audit",1)->sum("amount_cn");
            $this->assign("record",$record);
            $this->assign("times",$times);
            $this->assign("money",$money);
            return $this->fetch();
        }

    }

}